package indi.dos;

import static org.junit.jupiter.api.Assertions.*;

import java.util.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import indi.entity.Title;
import indi.service.BookSystem;
import indi.service.TitleService;
import indi.util.Common;

class TestTitleService {

	@BeforeEach
	void setUp() throws Exception {
	}

	@AfterEach
	void tearDown() throws Exception {
	}

	//@Test
	void test() {
		System.out.println("测试开始");
		
		TitleService ts = new TitleService();
		ArrayList<Title> titles = new ArrayList<>();
		titles.add(new Title("001", "作者1", 20, "书1", (float)23.5, "类型1"));
		titles.add(new Title("002", "作者2", 20, "书2", (float)253, "类型2"));
		titles.add(new Title("003", "作者3", 20, "书3", (float)23, "类型3"));
		titles.add(new Title("004", "作者4", 20, "书4", (float)233.5, "类型4"));

		ts.addTitles(titles);
		
		titles = null;
		titles = ts.getCurrentTitles();
		// 判断
		assertEquals(4, titles.size());
		System.out.println("添加后");
		ts.outputTitles(titles);
		
		while(true) {
			System.out.println("输入删除选项：");
			Scanner s = new Scanner(System.in);
			String id = s.next();
			ts.removeTitles(id);
			
			if(id.equals("end")) {
				break;
			}
//			ts.outputTitles(titles);
		}
		titles = ts.getCurrentTitles();
		ts.outputTitles(titles);
		System.out.println("测试结束");
	}
	@Test
	public void test1() {
		Scanner input = new Scanner(System.in);
		boolean isGoOn = true;
		int choice = 0;
		TitleService ts = new TitleService();
		
//		ArrayList<Title> titles = new ArrayList<>();
//		titles.add(new Title("001", "作者1", 20, "书1", (float)23.5, "类型1"));
//		titles.add(new Title("002", "作者2", 20, "书2", (float)253, "类型2"));
//		titles.add(new Title("003", "作者3", 20, "书3", (float)23, "类型3"));
//		titles.add(new Title("004", "作者4", 20, "书4", (float)233.5, "类型4"));
//
//		ts.addTitles(titles);
		
		while(isGoOn){
			TitleService.menu();
			System.out.print("输入：");
			choice = input.nextInt();
			
			switch(choice){
			case 1:
			{
				
//				new Title("001", "作者1", 20, "书1", (float)23.5, "类型1")
//				ts.addTitles(titles);
			
			}
			case 2:
				
			case 3:
			case 10:
				ArrayList<Title> titles1 = ts.getCurrentTitles();
				for(Title e: titles1) {
					Common.println(e.toString());
				}
				break;
			default:
				isGoOn = false;
				break;	
			}
		}
	}
}
